//
//  FDMSearchDetailTableViewCell.m
//  Entertainment
//
//  Created by dllo on 16/4/28.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMSearchDetailTableViewCell.h"
#import "FDMSearchDetailModel.h"

@interface FDMSearchDetailTableViewCell ()

@property (nonatomic, retain) UIImageView *titleImage;
@property (nonatomic, retain) FDMBaseLabel *titleLabel;
@property (nonatomic, retain) FDMBaseLabel *subTitleLabel;
@property (nonatomic, retain) FDMBaseLabel *playCountLabel;
@property (nonatomic, retain) FDMBaseLabel *trackLabel;

@end
@implementation FDMSearchDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createTableViewCell];
    }
    return self;
}

- (void)dealloc {
    [self.titleImage release];
    [self.titleLabel release];
    [self.subTitleLabel release];
    [self.playCountLabel release];
    [self.trackLabel release];
    [super dealloc];
}

- (void)createTableViewCell {
    self.titleImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.titleImage];
    [self.titleImage release];
    self.titleLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel release];
    self.subTitleLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.subTitleLabel];
    [self.subTitleLabel release];
    self.playCountLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.playCountLabel];
    [self.playCountLabel release];
    self.trackLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.trackLabel];
    [self.trackLabel release];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.contentView.mas_top).with.offset(10);
    make.left.equalTo(self.contentView.mas_left).with.offset(10);
    make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
    make.width.mas_equalTo(@80);
        }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.contentView.mas_top).with.offset(20);
    make.left.equalTo(self.titleImage.mas_right).with.offset(10);
    make.bottom.equalTo(self.contentView.mas_top).with.offset(30);
    make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 110));
        }];
    self.subTitleLabel.font = [UIFont systemFontOfSize:14];
    self.subTitleLabel.textColor = [UIColor grayColor];
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.titleLabel.mas_bottom).with.offset(10);
    make.left.equalTo(self.titleImage.mas_right).with.offset(10);
    make.bottom.equalTo(self.titleLabel.mas_bottom).with.offset(20);
    make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 110));
        }];
    
    self.playCountLabel.font = [UIFont systemFontOfSize:14];
    self.playCountLabel.textColor = [UIColor grayColor];
    [self.playCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.contentView.mas_bottom).with.offset(-40);
    make.left.equalTo(self.titleImage.mas_right).with.offset(10);
    make.bottom.equalTo(self.contentView.mas_bottom).with.offset(- 20);
    make.width.mas_equalTo(@((CONTENTVIEW_WIDTH - 110) / 2));
        }];
    
    self.trackLabel.font = [UIFont systemFontOfSize:14];
    self.trackLabel.textColor = [UIColor grayColor];
    [self.trackLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.contentView.mas_bottom).with.offset(-40);
    make.right.equalTo(self.contentView.mas_right).with.offset(-10);
    make.bottom.equalTo(self.contentView.mas_bottom).with.offset(- 20);
    make.width.mas_equalTo(@((CONTENTVIEW_WIDTH - 110) / 2));
        }];
}

- (void)setModel:(FDMSearchDetailModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
        self.titleLabel.text = _model.title;
        [self.titleImage sd_setImageWithURL:[NSURL URLWithString:_model.cover_path] placeholderImage:PLACEHOLDER_IMAGE];
        self.subTitleLabel.text = _model.intro;
        self.playCountLabel.text = [NSString stringWithFormat:@"播放次数：%@", _model.play];
        self.trackLabel.text = [NSString stringWithFormat:@"%@集",_model.tracks];
    }
}

@end
